package com.frxuexi.lib_base.base

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.BaseApp
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

open class BaseActivtiy:ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        startHandle()
    }

    private fun startHandle() {
        BaseApp.baseViewModel.apply {
            viewModelScope.launch {
                exception.flowWithLifecycle(lifecycle = lifecycle).collect{ex->
                    Log.i("===","网络错误${ex.message}")
                }
            }

            /*viewModelScope.launch {
                error.flowWithLifecycle(lifecycle = lifecycle).collect{
                    it.apply {
                        ToastUtils.showLong(it.msg)
                    }
                }
            }*/
        }
    }
}